package users;
//TODO: NEEDS IMPROVED COMMENTS

import java.awt.Color;
import java.io.Serializable;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Observable;

/**
 * Um, I dunno. It's not done yet. :P
 * @author Lois Fozzard
 *
 */
@SuppressWarnings("serial")
public class User extends Observable implements Serializable, Comparable<User>
{	
	private UserIdCard card;
	protected String ipAddress;
	private String username;
	private UserPermissions permissions;
	
	private Color color;
	
	/**
	 * Creates a user with the given name
	 * @param name a String of the User's name
	 */
	public User(String name, Color color){
		card = new UserIdCard();
		username = name;
		this.color = color;
		try
		{
			ipAddress = InetAddress.getLocalHost().getHostName();
		} catch (UnknownHostException e){}
        permissions = new UserPermissions();
	}
	
	/**
	 * returns the User's name
	 * @return the User's name
	 */
	public String getName(){
		return username;
	}
	
	/**
	 * returns the User's Color
	 * @return the User's Color
	 */
	public Color getColor(){
		return color;
	}
	
	/**
	 * Sets the User's Color
	 * @param c the color to set
	 */
	public void setColor(Color c){
		color = c;
		this.setChanged();
		this.notifyObservers();
	}
	
	public UserPermissions getUserPermissions()
	{
	    return permissions;
	}
	
	public void setUserPermissions(UserPermissions p)
	{
	    permissions = p;
        this.setChanged();
        this.notifyObservers();
	}
	
	public boolean equals(Object other)
	{
		if(other instanceof User)
			return card.equals(((User)other).card);
		return false;
	}

	public int compareTo(User user)
	{
		return card.compareTo(user.card);
	}
	
	public String toString()
	{
		return username;
	}
}
